#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e6;
typedef long long LL;
inline LL read()
{
	LL x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
struct rec{
	LL start,en,p;
}edge[maxn];
bool operator <(rec a,rec b)
{
	return a.p<b.p;
}
LL fa[maxn],n,m,ans=0,cnt=0;
LL find(LL x)
{
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  n=read();m=read();
  for(LL i=1;i<=m;i++){
    LL u,v,cost;u=read();v=read();cost=read();
    edge[++cnt].start=u;edge[cnt].en=v;edge[cnt].p=cost;
  }
  sort(edge+1,edge+1+cnt);
  for(LL i=1;i<=n;i++) fa[i]=i;
  for(LL i=1;i<=cnt;i++){
    LL x=find(edge[i].start);
    LL y=find(edge[i].en);
    if(x==y) continue;
    fa[find(x)]=find(y);
  }
  LL pos=0;
  for(LL i=1;i<=cnt;i++){
    if(edge[i].start==1){
        pos=i;
    }
  }
  LL big=find(edge[pos].start);
  for(LL i=1;i<=cnt;i++){
    if(find(edge[i].start)==big||find(edge[i].en)==big){
        ans=max(ans,edge[i].p);
    }
  }
  cout<<ans<<endl;
return 0;
}
